const {Service}=require("egg")

class UserService extends Service{

    async getSocket(){
        const sql=`select * from article`
        return await this.app.mysql.query(sql)
    }

    // 模糊搜索
    async filterList(text){
        const sql=`select * from user_list where username like "%${text}%"`
        return await this.app.mysql.query(sql,[text])
    }

    // 删除;
    async destroy(id){
        const sql=`delete from user_list where id=?`
        return await this.app.mysql.query(sql,[id])
    }

    // 查看
    async show(id){
        const sql=`select * from user_list where id=?`
        return await this.app.mysql.query(sql,[id])
    }

    // 编辑
    async update(id,username,nickname,age){
        const sql=`update user_list set username=?, nickname=?, age=? where id=?`
        return await this.app.mysql.query(sql,[username,nickname,age,id])
    }

    // 增加;
    async create(id,username,nickname,age){
        const sql=`insert into user_list (id,username,nickname,age) values (?,?,?,?)`
        return await this.app.mysql.query(sql,[id,username,nickname,age])
    }

    // 获取数据;
    async index(){
        const sql=`select * from user_list`
        return await this.app.mysql.query(sql)
    }

    // 判断;
    async changeName(username){
        const sql=`select * from login where username=?`
        return await this.app.mysql.query(sql,[username])
    }

    // 注册;
    async registry(id,username,pwd){
        const sql=`insert into login (id,username,pwd) values (?,?,?)`
        return await this.app.mysql.query(sql,[id,username,pwd])
    }

    // 登录
    async login(username,pwd){
        const sql=`select * from login where username=? and pwd=?`
        return await this.app.mysql.query(sql,[username,pwd])
    }
}

module.exports=UserService